//
//  VisitorView.m
//  weibo
//
//  Created by qiuming on 15/12/22.
//  Copyright © 2015年 qiuming. All rights reserved.
//

#import "VisitorView.h"
#import <Masonry.h>
#import "Extensions.h"


@interface VisitorView()
/// 遮罩图像
@property (strong, nonatomic) UIImageView *maskImageView;
/// 图标
@property (strong, nonatomic) UIImageView *iconView;
/// 小房子
@property (strong, nonatomic) UIImageView *homeIconView;
/// 提示标签
@property (strong, nonatomic) UILabel *messageLabel;

@end

@implementation VisitorView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self == [super initWithFrame:frame]) {
        // 设置界面
        [self setupUI];
    }
    return self;
}

// 设置访客视图的信息
- (void)visitorInfoWithImageName:(NSString *)imageName message:(NSString *)message {
    self.messageLabel.text = message;
    
    self.homeIconView.hidden = (imageName != nil);
    
    if (imageName != nil) {
        self.iconView.image = [UIImage imageNamed:imageName];
        [self sendSubviewToBack:self.maskImageView];
    } else {
        [self startAnimation];
    }
}

/// 添加动画
- (void)startAnimation {
    
    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    
    anim.toValue = @(2 * M_PI);
    anim.repeatCount = MAXFLOAT;
    anim.duration = 20.0;
    anim.removedOnCompletion = NO;
    
    [self.iconView.layer addAnimation:anim forKey:nil];
}

/// 设置界面
- (void)setupUI {
    
    self.backgroundColor = [UIColor colorWithWhite:237.0/255.0 alpha:1.0];
    // 1.添加控件
    [self addSubview:self.iconView];
    [self addSubview:self.homeIconView];
    [self addSubview:self.maskImageView];
    [self addSubview:self.messageLabel];
    [self addSubview:self.registerBtn];
    [self addSubview:self.loginBtn];
    
    // 2.自动布局
    [self.maskImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.left.equalTo(self.mas_left);
        make.bottom.equalTo(self.registerBtn.mas_bottom);
        make.right.equalTo(self.mas_right);
    }];
    
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.centerY.equalTo(self.mas_centerY).offset(-60);
    }];
    
    [self.homeIconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.iconView.mas_centerX);
        make.centerY.equalTo(self.iconView.mas_centerY);
    }];
    
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.iconView.mas_centerX);
        make.top.equalTo(self.iconView.mas_bottom).offset(16);
        make.size.mas_equalTo(CGSizeMake(224, 35));
    }];
    
    [self.registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.messageLabel.mas_bottom).offset(16);
        make.left.equalTo(self.messageLabel.mas_left);
        make.size.mas_equalTo(CGSizeMake(100, 35));
    }];
    
    [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.messageLabel.mas_bottom).offset(16);
        make.right.equalTo(self.messageLabel.mas_right);
        make.size.mas_equalTo(CGSizeMake(100, 35));
    }];
    
}



// MARK: - 懒加载
- (UIImageView *)maskImageView {
    if (_maskImageView == nil) {
        _maskImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
    }
    return _maskImageView;
}

- (UIImageView *)iconView {
    if (_iconView == nil) {
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
    }
    return _iconView;
}

- (UIImageView *)homeIconView {
    if (_homeIconView == nil) {
        _homeIconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
    }
    return _homeIconView;
}

- (UILabel *)messageLabel {
    if (_messageLabel == nil) {
        
        _messageLabel = [UILabel labelWithText:@"关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜" textColor:[UIColor darkGrayColor] textFont:14];
    }
    return _messageLabel;
}

- (UIButton *)registerBtn {
    if (_registerBtn == nil) {
        
        _registerBtn = [UIButton btnWithTitle:@"注册" titleColor:[UIColor orangeColor] backgroundImage:@"common_button_white_disable"];
    }
    return _registerBtn;
}

- (UIButton *)loginBtn {
    if (_loginBtn == nil) {
        
        _loginBtn = [UIButton btnWithTitle:@"登录" titleColor:[UIColor orangeColor] backgroundImage:@"common_button_white_disable"];
    }
    return _loginBtn;
}

@end













